(ns forum.core
  (:use net.cgrand.moustache
        forum.controller
        ring.middleware.file
        ring.middleware.params
        ring.middleware.session
        ring.middleware.session.cookie
        sandbar.stateful-session
        )
  (:require [ring.adapter.jetty :as jetty]))
 
;; Routes definition
(def routes
  (app
    (wrap-params)
    (wrap-file "resources")
    (wrap-stateful-session)
    ["login"]  (delegate login)
    ["logout"] (delegate logout)
    ["admin"] (delegate admin)
    ["category"] (delegate category)
    ["register"] (delegate register)
    ["thread"](delegate thread)
    ["addpost"](delegate addpost)
    ["viewusers"](delegate viewusers)
    ["edituser"](delegate edituser)
    ["editpost"](delegate editpost)
    ["edittopic"](delegate edittopic)
    ["viewnews"](delegate viewnews)
    ["addnews"](delegate addnews)
    ["submitnews"](delegate submitnews)
    ["inbox"](delegate inbox)
    ["outbox"](delegate outbox)
    ["sendm"](delegate sendm)
    ["search"](delegate search)
    ["searchp"](delegate searchp)
    [""] (delegate index)
    ["editu" user-id](delegate editu user-id)
    [category-id] (delegate topic category-id)
    ["post" topic-id] (delegate post topic-id)
    ["profile" user-id] (delegate profile user-id)
    ["deletepost" post-id](delegate deletepost post-id)
    ["editp" post-id](delegate editp post-id)
    ["editt" topic-id](delegate editt topic-id)
    ["deletetopic" topic-id](delegate deletetopic topic-id)
    ["quoterender" post-id](delegate quoterender post-id)
    ["message" message-id](delegate message message-id)
    ["sendmessage" user-id] (delegate sendmessage user-id)
    ["messagereply" message-id] (delegate messagereply message-id)
    ))
 
;;; start function for starting jetty
(defn start [port]
  (jetty/run-jetty #'routes {:port (or port 8080) :join? false}))

(start 8080)